package com.self.war.presenter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.myself.services.UserAuthenticationService;
import com.myself.services.exception.AuthenticationException;
import com.self.war.view.LoginView;
/**
 * 
 * Login view presenter
 * @see com.self.war.presenter.Presenter
 * @author kamel.mahdi
 *
 */
@SuppressWarnings("serial")
@Component
public class LoginPresenter implements Presenter<LoginView> {
	LoginView loginView;
	@Autowired
	UserAuthenticationService userAuthenticationService;

	@Override
	public LoginView getView() {
		return loginView;
	}

	@Override
	public void setView(LoginView view) {
		loginView = view;
	}

	public UserAuthenticationService getUserAuthenticationService() {
		return userAuthenticationService;
	}

	public void setUserAuthenticationService(
			UserAuthenticationService userAuthenticationService) {
		this.userAuthenticationService = userAuthenticationService;
	}

	/**
	 * Authenticate user 
	 * @param user : user login
	 * @param password : user password
	 * @return
	 */
	public boolean authenticateUser(String user, String password) {
		try {
			userAuthenticationService.authenticateUser(user, password);
			return true;
		} catch (AuthenticationException e) {
			return false;
		}
	}

}
